import { isMatchKeyDown } from '@/core/utils/is';
import { EDITOR_ELEMENT_TYPE, PLUGINS_KEYS, Plugin } from '../types';
import { KEYDOWNS } from '@/core/types';
import { Editor, Transforms } from 'slate';

function Indent(editor: Editor): Plugin {
  return {
    key: PLUGINS_KEYS.INDENT,
    type: EDITOR_ELEMENT_TYPE.BLOCK,
    match: () => false,
    priority: -1,
    onKeyDown: (event) => {
      if (isMatchKeyDown(event, KEYDOWNS.TAB)) {
        event.preventDefault();
        Transforms.insertText(editor, '\t');
      }
      return null;
    },
  };
}

export default Indent;
